﻿using FieldTools.Util;
using MahApps.Metro.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FieldTools.Client.View.Window
{
    /// <summary>
    /// WebViewControl.xaml 的交互逻辑
    /// </summary>
    public partial class WebViewWindow : MetroWindow, ITransientDependency
    {
        public WebViewWindow()
        {
            InitializeComponent();
            this.Closing += WebViewWindow_Closing;
        }

        public WebViewWindow(string url)
        {
            InitializeComponent();
            if (!string.IsNullOrEmpty(url))
            {
                urlTextBox.Text = url;
                if (webView.CoreWebView2 != null)
                {
                    webView.CoreWebView2.Navigate(url);
                }
                else
                {
                    webView.Source = new Uri(url);
                }
            }
            this.Closing += WebViewWindow_Closing;
        }

        private void WebViewWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
        {
            webView.Dispose();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(urlTextBox.Text))
            {
                webView.CoreWebView2.Navigate(urlTextBox.Text);
            }
        }
    }
}
